home *** CD-ROM | disk | FTP | other *** search
/ AGA Toolkit '97 / The AGA Toolkit '97.iso / text / misc / port / oldstuff / portsource.lha / Port101.S < prev    next >
Encoding:
Text File  |  1993-01-31  |  9.2 KB  |  671 lines

  1.     include    "src:shadowlord.i"
  2.  
  3. ; V1.01
  4. ; Added bigger understanding of PC box characters.
  5. ; Now also understands one-wide box chars, and thick corner changed to #,
  6. ; single corner to +.
  7.  
  8. * First: 2632
  9. * Clearing: 2588
  10. * 30-Jan-93
  11. * 6 days of hard coding
  12.  
  13. testmode    =    1
  14.  
  15.     if    testmode=1
  16.     lea    test_comline,a0
  17.     move.l    #test_len,d0
  18.     endc
  19.  
  20. progstart:
  21.     clr.b    -1(a0,d0.l)
  22.     move.l    a0,commandstart
  23.     move.w    d0,commandlen
  24.     add.l    d0,a0
  25.     subq.l    #1,a0
  26.     move.l    a0,commandend
  27.  
  28.     lea    dosname,a1
  29.     moveq    #0,d0
  30.     move.l    execbase,a6
  31.     jsr    openlibrary(a6)
  32.     move.l    d0,dosbase
  33.  
  34.     move.l    dosbase,a6
  35.     jsr    output(a6)
  36.     move.l    d0,outstruct
  37.  
  38.     move.l    #text_cursoroff,d2
  39.     moveq    #5,d3
  40.     bsr    printtext
  41.  
  42.     move.l    commandstart,a0
  43.     tst.b    (a0)            ; if blank commandline, instructions
  44.     beq    credits
  45.     cmp.b    #"?",(a0)
  46.     beq    credits
  47.  
  48. parse:
  49.     cmp.b    #" ",1(a0)        ; at least one space after option
  50.     bne    err_badcomline
  51.     cmp.b    #"p",(a0)
  52.     beq    frompcmode
  53.     cmp.b    #"P",(a0)
  54.     beq    topcmode
  55.     cmp.b    #"s",(a0)
  56.     beq    fromsf7mode
  57.     cmp.b    #"S",(a0)
  58.     beq    tosf7mode
  59.     bra    err_badcomline
  60.  
  61. frompcmode:
  62.     move.b    #1,mode
  63.     bra    nameparse
  64.  
  65. fromsf7mode:
  66.     move.b    #2,mode
  67.     bra    nameparse
  68.  
  69. tosf7mode:
  70.     move.b    #-2,mode
  71.     bra    nameparse
  72.  
  73. topcmode:
  74.     move.b    #-1,mode
  75.     bra    nameparse
  76.  
  77. nameparse:
  78.     addq.l    #1,a0
  79.     bsr    skipspace
  80.     cmp.l    #0,a0
  81.     beq    err_badcomline
  82.     move.l    a0,sourcenamestart
  83.     bsr    findend
  84.     cmp.l    #0,a0
  85.     beq    err_badcomline
  86.     move.l    a0,sourcenameend
  87.     addq.l    #1,a0
  88.     sub.l    sourcenamestart,a0
  89.     move.l    a0,sourcenamelen
  90.  
  91.     move.l    sourcenamestart,a0
  92.     move.l    #sourcename,a1
  93.     move.l    sourcenamelen,d0
  94.     subq.l    #1,d0
  95.     cmp.b    #'"',(a0)
  96.     beq    removequotes
  97.  
  98. copysourcename:
  99.     move.b    (a0)+,(a1)+
  100.     dbf    d0,copysourcename
  101.     clr.b    (a1)
  102.  
  103.     move.l    sourcenameend,a0
  104.     addq.l    #1,a0
  105.     cmp.l    commandend,a0
  106.     beq    nodest
  107.  
  108.     bsr    skipspace
  109.     cmp.l    #0,a0
  110.     beq    err_badcomline
  111.     move.l    a0,destnamestart
  112.     bsr    findend
  113.     cmp.l    #0,a0
  114.     beq    err_badcomline
  115.     move.l    a0,destnameend
  116.     addq.l    #1,a0
  117.     sub.l    destnamestart,a0
  118.     move.l    a0,destnamelen
  119.     move.l    a0,d0
  120.  
  121.     move.l    destnamestart,a0
  122.     move.l    #destname,a1
  123.     subq.l    #1,d0
  124.     cmp.b    #'"',(a0)
  125.     beq    removequotes1
  126.  
  127. copydestname:
  128.     move.b    (a0)+,(a1)+
  129.     dbf    d0,copydestname
  130.     bra    openfiles
  131.  
  132. removequotes:
  133.     addq.l    #1,a0
  134.     subq.l    #2,d0
  135.     bra    copysourcename
  136.  
  137. removequotes1:
  138.     addq.l    #1,a0
  139.     subq.l    #2,d0
  140.     bra    copydestname
  141.  
  142. removequotes2:
  143.     addq.l    #1,a0
  144.     subq.l    #2,d0
  145.     bra    copydestname1
  146.  
  147. nodest:
  148.     move.l    #destname,a1
  149.     move.l    sourcenamestart,a0
  150.     move.l    sourcenamelen,d0
  151.     subq.l    #1,d0
  152.     cmp.b    #'"',(a0)
  153.     beq    removequotes2
  154.  
  155. copydestname1:
  156.     move.b    (a0)+,(a1)+
  157.     dbf    d0,copydestname1
  158.  
  159.     cmp.b    #-1,mode
  160.     beq    pcsuffix
  161.     cmp.b    #-2,mode
  162.     beq    sf7suffix
  163.  
  164. amigasuffix:
  165.     lea    text_amigasuf,a0
  166.     moveq    #4-1,d0
  167.  
  168. amigasuffix1:
  169.     move.b    (a0)+,(a1)+
  170.     dbf    d0,amigasuffix1
  171.     bra    openfiles
  172.  
  173. pcsuffix:
  174.     lea    text_pcsuf,a0
  175.     moveq    #3-1,d0
  176.  
  177. pcsuffix1:
  178.     move.b    (a0)+,(a1)+
  179.     dbf    d0,pcsuffix1
  180.     bra    openfiles
  181.  
  182. sf7suffix:
  183.     lea    text_sf7suf,a0
  184.     moveq    #4-1,d0
  185.  
  186. sf7suffix1:
  187.     move.b    (a0)+,(a1)+
  188.     dbf    d0,sf7suffix1
  189.  
  190. openfiles:
  191.     clr.b    (a1)            ; end of filename
  192.     move.l    #sourcename,d1
  193.     move.l    #1005,d2
  194.     move.l    dosbase,a6
  195.     jsr    open(a6)
  196.     tst.l    d0
  197.     beq    err_nosource
  198.     move.l    d0,sourcehandle
  199.  
  200.     move.l    #destname,d1
  201.     move.l    #1006,d2
  202.     move.l    dosbase,a6
  203.     jsr    open(a6)
  204.     tst.l    d0
  205.     beq    err_nodest
  206.     move.l    d0,desthandle
  207.  
  208. readblock:
  209.     move.l    sourcehandle,d1
  210.     move.l    #sourcebuf,d2
  211.     move.l    #1024,d3
  212.     move.l    dosbase,a6
  213.     jsr    read(a6)
  214.     move.l    d0,d1
  215.     beq    closefiles
  216.     subq.l    #1,d1
  217.     moveq    #0,d2
  218.  
  219.     lea    sourcebuf,a0
  220.     lea    destbuf,a1
  221.  
  222. morecharacters:
  223.     move.b    (a0)+,d0
  224.     cmp.b    #-2,mode
  225.     beq    tosf7
  226.     cmp.b    #-1,mode
  227.     beq    topc
  228.     cmp.b    #2,mode
  229.     beq    fromsf7
  230.  
  231. frompc:
  232.     cmp.b    #$84,d0
  233.     beq    ami_lowae
  234.     cmp.b    #$94,d0
  235.     beq    ami_lowoe
  236.     cmp.b    #$8e,d0
  237.     beq    ami_upae
  238.     cmp.b    #$99,d0
  239.     beq    ami_upoe
  240.     cmp.b    #13,d0
  241.     beq    nochar
  242.     cmp.b    #0,d0
  243.     beq    nochar
  244.     cmp.b    #$1a,d0            ; ctrl+z
  245.     beq    nochar
  246.     cmp.b    #$c9,d0
  247.     beq    ami_bigcorner
  248.     cmp.b    #$bb,d0
  249.     beq    ami_bigcorner
  250.     cmp.b    #$c8,d0
  251.     beq    ami_bigcorner
  252.     cmp.b    #$bc,d0
  253.     beq    ami_bigcorner
  254.     cmp.b    #$cd,d0
  255.     beq    ami_doubleline
  256.     cmp.b    #$ba,d0
  257.     beq    ami_upline
  258.     cmp.b    #$b3,d0
  259.     beq    ami_upline
  260.     cmp.b    #$b0,d0
  261.     beq    ami_box
  262.     cmp.b    #$b1,d0
  263.     beq    ami_box
  264.     cmp.b    #$b2,d0
  265.     beq    ami_box
  266.     cmp.b    #$c4,d0
  267.     beq    ami_singleline
  268.     cmp.b    #$c0,d0
  269.     beq    ami_smallcorner
  270.     cmp.b    #$d9,d0
  271.     beq    ami_smallcorner
  272.     cmp.b    #$bf,d0
  273.     beq    ami_smallcorner
  274.     cmp.b    #$da,d0
  275.     beq    ami_smallcorner
  276.  
  277. nextchar:
  278.     move.b    d0,(a1)+
  279.     addq.l    #1,d2
  280.  
  281. nochar:
  282.     dbf    d1,morecharacters
  283.  
  284.     move.l    desthandle,d1
  285.     move.l    d2,d3
  286.     move.l    #destbuf,d2
  287.     move.l    dosbase,a6
  288.     jsr    write(a6)
  289.     bra    readblock
  290.  
  291. topc:
  292.     cmp.b    #"ä",d0
  293.     beq    pc_lowae
  294.     cmp.b    #"ö",d0
  295.     beq    pc_lowoe
  296.     cmp.b    #"Ä",d0
  297.     beq    pc_upae
  298.     cmp.b    #"Ö",d0
  299.     beq    pc_upoe
  300.     cmp.b    #10,d0
  301.     beq    addcr
  302.     cmp.b    #0,d0
  303.     beq    nochar
  304.     cmp.b    #$1a,d0            ; ctrl+z
  305.     beq    nochar
  306.     bra    nextchar
  307.  
  308. fromsf7:
  309.     cmp.b    #"{",d0
  310.     beq    ami_lowae
  311.     cmp.b    #"|",d0
  312.     beq    ami_lowoe
  313.     cmp.b    #"[",d0
  314.     beq    ami_upae
  315.     cmp.b    #"\",d0
  316.     beq    ami_upoe
  317.     cmp.b    #13,d0
  318.     beq    nochar
  319.     cmp.b    #0,d0
  320.     beq    nochar
  321.     cmp.b    #$1a,d0            ; ctrl+z
  322.     beq    nochar
  323.     bra    nextchar
  324.  
  325. tosf7:
  326.     cmp.b    #"ä",d0
  327.     beq    sf7_lowae
  328.     cmp.b    #"ö",d0
  329.     beq    sf7_lowoe
  330.     cmp.b    #"Ä",d0
  331.     beq    sf7_upae
  332.     cmp.b    #"Ö",d0
  333.     beq    sf7_upoe
  334.     cmp.b    #10,d0
  335.     beq    addcr
  336.     cmp.b    #0,d0
  337.     beq    nochar
  338.     cmp.b    #$1a,d0            ; ctrl+z
  339.     beq    nochar
  340.     bra    nextchar
  341.  
  342. ami_singleline:
  343.     move.b    #"-",d0
  344.     bra    nextchar
  345.  
  346. ami_box:
  347.     move.b    #$7f,d0
  348.     bra    nextchar
  349.  
  350. ami_upline:
  351.     move.b    #"|",d0
  352.     bra    nextchar
  353.  
  354. ami_doubleline:
  355.     move.b    #"=",d0
  356.     bra    nextchar
  357.  
  358. ami_smallcorner:
  359.     move.b    #"+",d0
  360.     bra    nextchar
  361.  
  362. ami_bigcorner:
  363.     move.b    #"#",d0
  364.     bra    nextchar
  365.  
  366. ami_lowae:
  367.     move.b    #"ä",d0
  368.     bra    nextchar
  369.  
  370. ami_lowoe:
  371.     move.b    #"ö",d0
  372.     bra    nextchar
  373.  
  374. ami_upae:
  375.     move.b    #"Ä",d0
  376.     bra    nextchar
  377.  
  378. ami_upoe:
  379.     move.b    #"Ö",d0
  380.     bra    nextchar
  381.  
  382. pc_lowae:
  383.     move.b    #$84,d0
  384.     bra    nextchar
  385.  
  386. pc_lowoe:
  387.     move.b    #$94,d0
  388.     bra    nextchar
  389.  
  390. pc_upae:
  391.     move.b    #$8e,d0
  392.     bra    nextchar
  393.  
  394. pc_upoe:
  395.     move.b    #$99,d0
  396.     bra    nextchar
  397.  
  398. sf7_lowae:
  399.     move.b    #"{",d0
  400.     bra    nextchar
  401.  
  402. sf7_lowoe:
  403.     move.b    #"|",d0
  404.     bra    nextchar
  405.  
  406. sf7_upae:
  407.     move.b    #"[",d0
  408.     bra    nextchar
  409.  
  410. sf7_upoe:
  411.     move.b    #"\",d0
  412.     bra    nextchar
  413.  
  414. addcr:
  415.     move.b    #13,(a1)+
  416.     addq.l    #1,d2
  417.     bra    nextchar
  418.  
  419. closefiles:
  420.     move.l    sourcehandle,d1
  421.     move.l    dosbase,a6
  422.     jsr    close(a6)
  423.     move.l    desthandle,d1
  424.     move.l    dosbase,a6
  425.     jsr    close(a6)
  426.     bra    endprogram1
  427.  
  428. credits:
  429.     move.l    #text_credits,d2
  430.     move.l    #len_credits,d3
  431.     bsr    printtext
  432.     bra    endprogram1
  433.  
  434. err_nosource:
  435.     move.l    #text_nosource,d2
  436.     moveq    #36,d3
  437.     bsr    printtext
  438.     bra    endprogram1
  439.  
  440. err_nomemory:
  441.     move.l    #text_nomemory,d2
  442.     moveq    #26,d3
  443.     bsr    printtext
  444.     bra    endprogram1
  445.  
  446. err_badcomline:
  447.     move.l    #text_badcomline,d2
  448.     moveq    #25,d3
  449.     bsr    printtext
  450.     bra    endprogram1
  451.  
  452. err_nodest:
  453.     move.l    #text_nodest,d2
  454.     moveq    #41,d3
  455.     bsr    printtext
  456.     bra    endprogram2
  457.  
  458. endprogram1:
  459.     move.l    #text_cursoron,d2
  460.     moveq    #5,d3
  461.     bsr    printtext
  462.  
  463.     move.l    execbase,a6
  464.     move.l    dosbase,a1
  465.     jsr    closelibrary(a6)
  466.     moveq    #0,d0
  467.     rts
  468.  
  469. endprogram2:
  470.     move.l    sourcehandle,d1
  471.     move.l    dosbase,a6
  472.     jsr    close(a6)
  473.     bra    endprogram1
  474.  
  475. **********
  476. ** SUBS **
  477. **********
  478.  
  479. printtext:
  480.     if    testmode=1
  481.     rts
  482.     endc
  483.     move.l    outstruct,d1
  484.     move.l    dosbase,a6
  485.     jsr    write(a6)
  486.     rts
  487.  
  488. skipspace:
  489.     cmp.b    #" ",(a0)
  490.     beq    skipspace1
  491.     rts
  492.  
  493. skipspace1:
  494.     add.l    #1,a0
  495.     cmp.l    commandend,a0
  496.     bcs    skipspace
  497.     move.l    #0,a0
  498.     rts
  499.  
  500. findend:
  501.     cmp.b    #'"',(a0)
  502.     beq    findend_quote
  503.  
  504. findend_space:
  505.     addq.l    #1,a0
  506.     cmp.b    #" ",(a0)
  507.     beq    findend_space1
  508.     cmp.b    #0,(a0)
  509.     beq    findend_space1
  510.     cmp.l    commandend,a0
  511.     bls    findend_space
  512.     move.l    #0,a0
  513.     rts
  514.  
  515. findend_space1:
  516.     subq.l    #1,a0
  517.     rts
  518.  
  519. findend_quote:
  520.     addq.l    #1,a0
  521.     cmp.b    #'"',(a0)
  522.     bne    findend_quote1
  523.     rts
  524.  
  525. findend_quote1:
  526.     cmp.l    commandend,a0
  527.     bls    findend_quote
  528.     move.l    #0,a0
  529.     rts
  530.  
  531.  
  532. **********
  533. ** DATA **
  534. **********
  535.  
  536.     section    fastdata,data
  537.  
  538. text_credits:
  539.     dc.b    27,"[1m"
  540.     dc.b    "Port V1.01  (31-Jan-93)",10
  541.     dc.b    "Copyright © 1993 by Henrik Tikanvaara",10
  542.     dc.b    27,"[0m",10
  543.     dc.b    10
  544.     dc.b    "Usage: Port <Mode> <Source> [Dest]",10
  545.     dc.b    10
  546.     dc.b    27,"[1m"
  547.     dc.b    "  Mode"
  548.     dc.b    27,"[0m"
  549.     dc.b    " Conversion mode.",10
  550.     dc.b    "       s = SF7->Amiga",10
  551.     dc.b    "       p = PC ->Amiga",10
  552.     dc.b    "       S = Amiga->SF7",10
  553.     dc.b    "       P = Amiga->PC",10
  554.     dc.b    27,"[1m"
  555.     dc.b    "Source"
  556.     dc.b    27,"[0m"
  557.     dc.b    " The source filename to be converted.",10
  558.     dc.b    27,"[1m"
  559.     dc.b    "  Dest"
  560.     dc.b    27,"[0m"
  561.     dc.b    " The optional destination filename for the converted",10
  562.     dc.b    "       text.  Otherwise the filename will have a suffix",10
  563.     dc.b    "       related to the mode.",10
  564.     dc.b    10
  565.     dc.b    "If you have an idea of something you'd want to see in this",10
  566.     dc.b    "program, please send me a note.",10
  567.     dc.b    10
  568.     dc.b    "InterNet: sl@field.ichaos.nullnet.fi",10
  569.  
  570. text_cursoroff:
  571.     dc.b    27,"[0 p"
  572.  
  573. text_cursoron:
  574.     dc.b    27,"[1 p"
  575.  
  576. text_badcomline:
  577.     dc.b    "ERROR!  Bad commandline.",10
  578.  
  579. text_nomemory:
  580.     dc.b    "ERROR!  Not enough memory.",10
  581.  
  582. text_badsource:
  583.     dc.b    "ERROR!  Bad sourcefile.",10
  584.  
  585. text_nosource:
  586.     dc.b    "ERROR!  Could not open source file.",10
  587.  
  588. text_nodest:
  589.     dc.b    "ERROR!  Could not open destination file.",10
  590.  
  591. dosname:
  592.     dc.b    "dos.library",0
  593.  
  594. text_amigasuf:
  595.     dc.b    ".AMI"
  596.  
  597. text_pcsuf:
  598.     dc.b    ".PC"
  599.  
  600. text_sf7suf:
  601.     dc.b    ".SF7"
  602.  
  603.     if    testmode=1
  604.  
  605. test_comline:
  606.     dc.b    'a    "dh1:tes. txt"   "dh1:tes su.xx"',10
  607. ;    dc.b    "a dh1:tests.txt dh1:testd.txt",10
  608.  
  609. test_comlineend:
  610.  
  611. test_len    =    test_comlineend-test_comline
  612.     endc
  613.  
  614.     section    fastblank,bss
  615.  
  616. sourcehandle:
  617.     ds.l    1
  618.  
  619. desthandle:
  620.     ds.l    1
  621.  
  622. outstruct:
  623.     ds.l    1
  624.  
  625. destnamestart:
  626.     ds.l    1
  627.  
  628. destnameend:
  629.     ds.l    1
  630.  
  631. destnamelen:
  632.     ds.l    1
  633.  
  634. sourcenamestart:
  635.     ds.l    1
  636.  
  637. sourcenameend:
  638.     ds.l    1
  639.  
  640. sourcenamelen:
  641.     ds.l    1
  642.  
  643. commandstart:
  644.     ds.l    1
  645.  
  646. commandend:
  647.     ds.l    1
  648.  
  649. commandlen:
  650.     ds.l    1
  651.  
  652. dosbase:
  653.     ds.l    1
  654.  
  655. mode:
  656.     ds.b    1
  657.  
  658. sourcename:
  659.     ds.b    256
  660.  
  661. destname:
  662.     ds.b    256
  663.  
  664. sourcebuf:
  665.     ds.b    1024
  666.  
  667. destbuf:
  668.     ds.b    2048
  669.  
  670. len_credits    =    text_cursoroff-text_credits
  671.